//
//  NationalBondsJaList.m
//  MarketDataColloctor
//
//  Created by jiro on 10/03/27.
//  Copyright 2010 jiro music. All rights reserved.
//

#import "NationalBondsJaList.h"
#import "NationalBondsJa.h"


@implementation NationalBondsJaList

+ (NationalBondsJaList*) nationalBondsJaListWithPgResult: (PGresult*) res
{
	NationalBondsJaList* list = [ [ NationalBondsJaList alloc ] init ];
	
	int row = PQntuples( res );
	int column = PQnfields( res );
	for ( int i = 0; i < row; i++ ) 
	{
		NSMutableArray* values = [ NSMutableArray array ];
		for ( int j = 0; j < column; j++ )
		{
			[ values addObject: [ NSString stringWithFormat: @"%s", PQgetvalue( res, i, j ) ] ];
		}
		NationalBondsJa* value = [ NationalBondsJa nationalBondsJaWithValues: values ];
		[ list addObject: value ];
	}
	return list;
}

- (NSString*) sqlInsertStatement
{
	NSMutableString* sql = [ NSMutableString string ];
	[ sql appendFormat: @"insert into %@ values\n", [ NationalBondsJa tableName ] ];
	NSEnumerator* e = [ self objectEnumerator ];
	NationalBondsJa* value;
	BOOL firstValue = YES;
	while ( value = [ e nextObject ] )
	{
		if ( firstValue ) {
			firstValue = NO;
		} else {
			[ sql appendString: @", " ];
		}
		[ sql appendFormat: @"%@\n", [ value queryInsertValue ] ];
	}
	[ sql appendString: @";\n" ];	
	return sql;
}

@end
